var app = getApp(),
  $ = require("../../utils/httpHelper.js")
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    meeting_info: {},
    list: [],
    member_id: 0,
    address:'',
    lat:'',
    lng:''
  },

  onLoad: function (options) {
    if (options.scene) {
      this.setData({
        member_id: options.scene
      })
    }

    //实例化API核心类
    var dw = new QQMapWX({
      key: 'WSSBZ-5HXWF-FB3JM-JW5ZC-AML57-4BFO3' // 必填
    });
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        //经纬度转地区名
        dw.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          complete: function (res) {
            console.log(res);
            let address = res.result.address
            this.setData({
              address:address,
              lat: latitude,
              lng: longitude
            })
          }
        });
      }
    })

    app.ajax("meeting_info", { rd_session: wx.getStorageSync('rd_session'), meeting_id: this.data.member_id }, (data, err) => {
      if (data.result == 'success') {
        this.setData({
          meeting_info: data.data,
        })
      } else {
        wx.showModal({
          title: '提示',
          content: data.message,
        })
      }
    })

  },

  sign(){
    let par = {
      rd_session: wx.getStorageSync("rd_session"),
      address:this.data.address,
      latitude:this.data.lat,
      longitude:this.data.lng,
      meeting_id: this.data.member_id
    }
    app.ajax("sign_meeting", par, (data, err) => {
      if (data.result == 'success') {
        if (data.data.is_late){
          wx.showToast({
            title: '您已迟到！',
          })
        }
      }else{
        wx.showModal({
          title: '提示',
          content: data.message,
        })
      }
    })
  }

});